/*
 * Copyright (c) 2015 elion. All Rights Reserved.
 */
package com.guoyu.project.service;

import com.google.common.collect.Maps;
import com.guoyu.project.common.pagination.Pagination;
import com.guoyu.project.dao.BanIpDao;
import com.guoyu.project.model.BanIp;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * banIp信息,业务类banIpService
 *
 * @author: xblibo Sat Jun 27 14:00:13 CST 2015
 * @version 1.0
 */
@Service
public class BanIpService {

    @Resource
    private BanIpDao banIpDao;

    /**
     * 保存banIp信息数据
     *
     * @param banIp
     */
    public void saveBanIp(BanIp banIp) {
        banIpDao.save(banIp);
    }

    /**
     * 更新banIp信息实体
     *
     * @param banIp
     */
    public void updateBanIp(BanIp banIp) {
        banIpDao.update(banIp);
    }

    /**
     * 删除banIp信息数据
     *
     * @param banIpId
     */
    public void deleteById(int banIpId) {
        banIpDao.deleteById(banIpId);
    }

    /**
     * 根据id获取banIp信息数据
     *
     * @param banIpId
     * @return
     */
    public BanIp queryById(int banIpId) {
        return banIpDao.queryById(banIpId);
    }

    /**
     * 根据条件分页查询banIp信息数据
     *
     * @param offset
     * @param limit
     * @param params
     * @return
     */
    public Pagination<BanIp> queryBanIps(int offset, int limit, Map<String, Object> params) {
        // 根据条件获取总记录数
        int total = banIpDao.queryBanIpCount(params);

        // 构建分页对象，参数
        if (null == params) {
            params = Maps.newHashMap();
        }
        params.put(Pagination.OFFSET, offset);
        params.put(Pagination.LIMIT, limit);

        // 分页查询数据
        List<BanIp> banIpList = banIpDao.queryBanIps(params);
        return new Pagination(offset, limit, total, banIpList);
    }

    public List<BanIp> queryBanIps(Map<String, Object> params) {
        return banIpDao.queryBanIps(params);
    }
}